﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CoreProject.IRepository;
using CoreProject.Model;
using Microsoft.EntityFrameworkCore;
namespace CoreProject.Repository
{
    public class AuthorityRepository : BaseRepository<Authority>, IAuthorityRepository
    {
        private readonly EFDbContext _dbContext;

        public AuthorityRepository(EFDbContext dbContext) : base(dbContext)
        {
            this._dbContext = dbContext;
        }

        public async Task<bool> AddAuth(int rid, List<Authority> list)
        {
            var data =await _dbContext.Authorities.Where(n=>n.RoleId==rid).ToListAsync();
            _dbContext.Authorities.RemoveRange(data);
            _dbContext.Authorities.AddRange(list);
            return await _dbContext.SaveChangesAsync()>0;
         
        }

        public async Task<List<Authority>> GetAuthListByRid(int rid)
        {
            return await _dbContext.Authorities.Include(n=>n.Menu).Where(n => n.RoleId == rid).ToListAsync();
        }
    }
}
